package com.example.springboot.config.registerBean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.stereotype.Component;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/4/2 13:54
 */
@Component
public class RegisterBeanFactory implements BeanDefinitionRegistryPostProcessor {
    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException {
        System.out.println("周杰伦");
        // 通用对象描述
        GenericBeanDefinition genericBeanDefinition=new GenericBeanDefinition();
        // 设置工厂类
        genericBeanDefinition.setBeanClass(ProxyBeanFactory.class);
        BeanDefinitionHolder beanDefinitionHolder=new BeanDefinitionHolder(genericBeanDefinition,"iUserDao");
        // 注册
        BeanDefinitionReaderUtils.registerBeanDefinition(beanDefinitionHolder,beanDefinitionRegistry);
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {

    }
}
